#include <stdio.h>
int main() 
{
	int m,n,a[12][12],s=0;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",a[i][j]);
			if(i==1||i==n||j==1||j==m) s+=a[i][j];
		}
	}
	printf("%d",s);
	return 0;
}

